package com.sgb.kjwl.view.ui.activity.manage;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.PopupWindow;

import androidx.annotation.Nullable;
import androidx.core.util.Pair;
import androidx.databinding.DataBindingUtil;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityIprDetailBinding;
import com.sgb.kjwl.di.manage.DaggerEnterpriseManageComponent;
import com.sgb.kjwl.di.manage.EnterpriseManageModule;
import com.sgb.kjwl.model.entity.manage.IPDetailEntity;
import com.sgb.kjwl.utils.ActivityJump;
import com.sgb.kjwl.view.ui.activity.packers.FindPackersActivity;
import com.sgb.kjwl.view.ui.activity.self.shop.ShopInfoActivity;
import com.sgb.kjwl.view.widget.PickPopWindow;
import com.sgb.kjwl.viewmodel.manage.IPDetailModel;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.dialog.BasePopWindow;

import javax.inject.Inject;

/**
 * note
 *
 * Create for
 *
 * Change for YangHao
 * Date 2021/6/21
 */
public class IPDetailActivity extends AppActivity {
    @Inject
    IPDetailModel viewModel;
    IPDetailEntity entity;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerEnterpriseManageComponent.builder().appComponent(appComponent)
                .enterpriseManageModule(new EnterpriseManageModule(this))
                .build()
                .inject(this);
    }

    public static void startAction(Context activity, IPDetailEntity entity) {
        Intent intent = new Intent(activity, IPDetailActivity.class);
        intent.putExtra("data", entity);
        activity.startActivity(intent);
    }


    @Override
    protected void initView() {
        super.initView();
        entity = (IPDetailEntity) getIntent().getSerializableExtra("data");
        com.sgb.kjwl.databinding.ActivityIprDetailBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_ipr_detail);
        binding.appBarLayout.ivBack.setOnClickListener(this);
        RequestOptions options = new RequestOptions().placeholder(R.drawable.null_img_list)
                .error(R.drawable.null_img_list);
        Glide.with(this).load(entity.getUploadPictures()).apply(options)
                .into((binding.imageView));
        binding.ipInfo.setText(entity.getName());
        if ("商标".equals(entity.getTypesOfPropertyRights())) {
            binding.appBarLayout.titleView.setText("商标详情");
            binding.specialType.setText("商标详情");
            binding.tvType.setText("商标类型");
            binding.tvBrand.setText("商标状态");
            binding.tvIndustryName.setVisibility(View.GONE);
            binding.tvIndustry.setVisibility(View.GONE);
            binding.tvBrandState.setVisibility(View.GONE);
            binding.tvBrand.setVisibility(View.GONE);
        } else if ("专利".equals(entity.getTypesOfPropertyRights())) {
            binding.appBarLayout.titleView.setText("专利详情");
            binding.specialType.setText("专利详情");
            binding.tvType.setText("专利类型");
            binding.tvBrand.setText("专利状态");
            binding.tvIndustryName.setVisibility(View.VISIBLE);
            binding.tvIndustry.setVisibility(View.VISIBLE);
            binding.tvBrandState.setVisibility(View.VISIBLE);
            binding.tvBrand.setVisibility(View.VISIBLE);
            binding.tvIndustryName.setText(entity.getFieldClassName());
            binding.tvBrandState.setText("1".equals(entity.getState()) ? "授权未下证" : " 授权已下证");
        } else {
            binding.appBarLayout.titleView.setText("版权详情");
            binding.specialType.setText("版权详情");
            binding.tvType.setText("版权类型");
            binding.tvBrand.setText("版权状态");
            binding.tvIndustryName.setVisibility(View.GONE);
            binding.tvIndustry.setVisibility(View.GONE);
            binding.tvBrandState.setVisibility(View.GONE);
            binding.tvBrand.setVisibility(View.GONE);
        }
        binding.tvTypeName.setText(entity.getType());
        binding.tvData.setText(entity.getApplicationDate());

        binding.btnEnterEnterprise.setOnClickListener(this);
        binding.appBarLayout.ivBack.setOnClickListener(this);
        binding.proposer.setText(entity.getCompanyName());
        binding.companyRegistration.setText(entity.getAddressNew());

    }

    @Override
    public void onMultiClick(View v) {
        super.onMultiClick(v);
        switch (v.getId()) {
            case R.id.btn_enter_enterprise:
                ActivityJump.jumpToActivity(this, ShopInfoForCompanyTradesActivity.class, Pair.create("id", entity.getCompanyId()), Pair.create("companyNo", entity.getCompanyNo()), Pair.create("position", 5), Pair.create("childPosition", 3));
                break;
            case R.id.iv_back:
                finish();
                break;
            default:
                break;
        }
    }
}
